package com.tian.recycler.itemtouch

import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.RecyclerView

/**
 * @author tiansongtao, Email:tiansongtao@up366.com
 * @date 2021/3/22 10:45
 */
class ItemTouchCallback : ItemTouchHelper.Callback() {

    var itemTouchAdapterCallback: ItemTouchAdapterCallback? = null

    override fun getMovementFlags(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder): Int {
        val dragFlags = ItemTouchHelper.UP or ItemTouchHelper.DOWN
        val swiperFlags = ItemTouchHelper.LEFT
        return makeMovementFlags(dragFlags, swiperFlags)
    }

    override fun onMove(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder, target: RecyclerView.ViewHolder): Boolean {
        itemTouchAdapterCallback?.onItemMove(viewHolder.adapterPosition, target.adapterPosition)
        return true
    }

    override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) {
        itemTouchAdapterCallback?.onItemDelete(viewHolder)
    }


    override fun isLongPressDragEnabled() = true

    override fun isItemViewSwipeEnabled() = true

    override fun getAnimationDuration(recyclerView: RecyclerView, animationType: Int, animateDx: Float, animateDy: Float): Long {
        return 200
    }

    override fun getSwipeEscapeVelocity(defaultValue: Float): Float {
        return  10000f
    }


}